package com.eastshop.seller.adminaction;

import java.util.List;

import com.eastshop.seller.dao.RegionDao;
import com.eastshop.seller.service.RegionService;
import com.eastshop.seller.vo.Region;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
/**
 * 后台小区管理的Action类
 * @author admin
 *
 */
public class AdminRegionAction extends ActionSupport implements ModelDriven<Region> {
	// 模型驱动使用的对象
	private Region region = new Region();

	public Region getModel() {
		return region;
	}
	
	// 注入小区的Service
	private RegionService regionService;

	public void setRegionService(RegionService regionService) {
		this.regionService = regionService;
	}
	
	// 查找所有服务的小区
	public String find(){
		List<Region> rList = regionService.findRegion();
		ActionContext.getContext().getValueStack().set("rList", rList);
		return "find";
	}
	
	// 删除小区的方法
	public String delete(){
		// 根据id查找小区
		region = regionService.findByRid(region.getRid());
		// 删除
		regionService.delete(region);
		return "delete";
	}
	
	// 跳转到添加小区的页面
	public String add(){
		return "add";
	}
	
	// 添加小区
	public String addSubmit(){
		regionService.save(region);
		return "addSubmit";
	}
	
	// 跳转到编辑页面
	public String edit(){
		// 根据id查找小区
		region = regionService.findByRid(region.getRid());
		return "edit";
	}
	
	// 更新小区信息
	public String editSubmit(){
		regionService.update(region);
		return "editSubmit";
	}
}
